package receivers;

import services.LoginService;
import services.RegisterService;
import tw.edu.tku.im.maze.RepPacket;

import com.example.maze.ConnectionInfo;
import com.example.maze.MainActivity;
import com.example.maze.R;
import com.example.maze.RegisterActivity;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class RegisterRepReceiver extends BroadcastReceiver {
   Activity currentUIActivity;
   
   public RegisterRepReceiver(Activity activity) {
      currentUIActivity= activity;
   }

   @Override
   public void onReceive(Context context, Intent intent) {
      // TODO Auto-generated method stub
      ((RegisterActivity)currentUIActivity).dismissMyDialog();
      int status= intent.getIntExtra(RegisterService.STATUS, -1); // -1: status not found
      
      switch(status) {
      case RegisterService.REGISTER_REP_STATE_SUCCESS: 
         ((RegisterActivity)currentUIActivity).showMsgDialog(R.string.a1_registerSuccess_ch);
         break;
      case RegisterService.REGISTER_REP_STATE_ERROR_ID: 
         ((RegisterActivity)currentUIActivity).showMsgDialog(R.string.a1_registerErrorId_ch);
         break;
      case RegisterService.REGISTER_REP_STATE_ERROR_ID_FORMAT:             
         ((RegisterActivity)currentUIActivity).showMsgDialog(R.string.a1_registerErrorIdFormat_ch);
         break;
      case RegisterService.REGISTER_REP_STATE_ERROR_NAME_FORMAT:             
         ((RegisterActivity)currentUIActivity).showMsgDialog(R.string.a1_registerErrorNameFormat_ch);
         break;   
      case RegisterService.REGISTER_REP_STATE_ERROR_PWD_FORMAT:             
         ((RegisterActivity)currentUIActivity).showMsgDialog(R.string.a1_registerErrorPwdFormat_ch);
         break;    
      default: 
         ((RegisterActivity)currentUIActivity).showMsgDialog(R.string.a1_connectionTimeout_ch);
      }
   }

}
